import { BasicColumn, FormSchema } from '/@/components/Table';
import { DictCodeEnum, getDictItems, getDictItemMap } from '/@/utils/dict';

// 操作日志状态字典数据
const operateLogStatusDict = getDictItems(DictCodeEnum.OPERATE_LOG_STATUS);
const operateLogStatusDictMap = getDictItemMap(DictCodeEnum.OPERATE_LOG_STATUS);

// 操作日志类型字典数据
const operateTypeDict = getDictItems(DictCodeEnum.OPERATE_TYPE);
const operateTypeDictMap = getDictItemMap(DictCodeEnum.OPERATE_TYPE);

// 请求类型字典数据
const requestMethodDict = getDictItems(DictCodeEnum.REQUEST_METHOD);

export const columns: BasicColumn[] = [
  {
    title: '模块名称',
    dataIndex: 'module',
  },
  {
    title: '操作方法',
    dataIndex: 'title',
  },
  {
    title: '业务类型',
    dataIndex: 'businessType',
    width: 80,
    dictFormat: operateTypeDictMap,
  },
  {
    title: '请求URL',
    dataIndex: 'requestUrl',
  },
  {
    title: '请求方式',
    width: 80,
    dataIndex: 'requestMethod',
  },
  {
    title: '主机IP',
    dataIndex: 'ip',
    width: 120,
  },
  {
    title: '操作地点',
    dataIndex: 'location',
  },
  {
    title: '操作人',
    dataIndex: 'optUser',
  },
  {
    title: '操作状态',
    dataIndex: 'optStatus',
    width: 80,
    dictFormat: operateLogStatusDictMap,
  },
  {
    title: '操作时间',
    dataIndex: 'createTime',
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'title',
    label: '模块标题',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    field: 'businessType',
    label: '业务类型',
    component: 'Select',
    componentProps: {
      options: operateTypeDict,
    },
    colProps: { span: 6 },
  },
  {
    field: 'requestMethod',
    label: '请求方式',
    component: 'Select',
    componentProps: {
      options: requestMethodDict,
    },
    colProps: { span: 6 },
  },
  {
    field: 'optStatus',
    label: '操作状态',
    component: 'Select',
    componentProps: {
      options: operateLogStatusDict,
    },
    colProps: { span: 6 },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'id',
    label: 'ID',
    component: 'Input',
    show: false,
  },
  {
    field: 'module',
    label: '模块标题',
    component: 'Input',
    componentProps: {
      readonly: true,
    },
  },
  {
    field: 'title',
    label: '操作方法',
    component: 'Input',
    componentProps: {
      readonly: true,
    },
  },
  {
    field: 'businessType',
    label: '业务类型',
    component: 'Select',
    componentProps: {
      options: operateTypeDict,
      disabled: true,
    },
  },
  {
    field: 'requestUrl',
    label: '请求URL',
    component: 'Input',
    componentProps: {
      readonly: true,
    },
  },
  {
    field: 'requestMethod',
    label: '请求方式',
    component: 'Input',
    componentProps: {
      readonly: true,
    },
  },
  {
    field: 'optUser',
    label: '操作人',
    component: 'Input',
    componentProps: {
      readonly: true,
    },
  },
  {
    field: 'ip',
    label: '主机IP',
    component: 'Input',
    componentProps: {
      readonly: true,
    },
  },
  {
    field: 'location',
    label: '操作地点',
    component: 'Input',
    componentProps: {
      readonly: true,
    },
  },
  {
    field: 'optStatus',
    label: '操作状态',
    component: 'Select',
    componentProps: {
      options: operateLogStatusDict,
      disabled: true,
    },
  },
  {
    field: 'method',
    label: '方法名称',
    component: 'Input',
    componentProps: {
      readonly: true,
    },
    colProps: { lg: 24, md: 24 },
  },
  {
    field: 'requestParam',
    label: '请求参数',
    component: 'InputTextArea',
    componentProps: {
      readonly: true,
    },
    colProps: { lg: 24, md: 24 },
  },
  {
    field: 'jsonResult',
    label: '返回参数',
    component: 'InputTextArea',
    componentProps: {
      readonly: true,
    },
    colProps: { lg: 24, md: 24 },
  },
  {
    field: 'errorMsg',
    label: '错误消息',
    component: 'InputTextArea',
    componentProps: {
      readonly: true,
    },
    colProps: { lg: 24, md: 24 },
  },
];
